#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <iostream>
#include <QDebug>
#include <QLabel>
#include <QTableWidget>
#include <QFile>
#include "other/user.h"
#include "interp.h"
#include "aboutwidget.h"
#include "createuserwidget.h"
#include "codeeditor.h"
#include "other/logs.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void toolBarInit();
    void stackWidgetInit();
    void treeWidgetInit();
    void tabWidgetInit();
    void tableWidgetInit(QTableWidget * tableWidget);
    void tableTreeWidgetInit(QTableWidget * tableWidget);
    void findTreeWidgetInit(QTableWidget * tableWidget);
    void userWidgetInit(QTableWidget * tableWidget);
    void createTableWidgetInit(QTableWidget * tableWidget);
    void absWidgetInit(QTableWidget * tableWidget);
    void dockWidgetInit();
    void openSql(QFile &file);
    void redBase(QString &str);
    QString pwdMD5(QString pwd);
    void removeComments(QString &text);
    void userInit();
    void interp_sql(const std::shared_ptr<ast::TreeNode> &root,QString cmd);

private slots:
    void on_actionAbout_triggered();
    void on_createFind_clicked();
    void on_actionUser_triggered();
    void on_createTable_clicked();
    void on_actionCDb_triggered();
    void on_showTable_clicked();
    void on_deleteTable_clicked();
    void on_alterTable_clicked();

    void on_actionSQl_triggered();

    void on_actionFind_triggered();

    void on_actionTable_triggered();

private:
    void createTable(const QString &tabName);
    void openTable(const QString &tabName);
    void dropTable(const QString &tabName);
    void createUserWidget();
    void createUser(const User &user);
    void changeUser(QTableWidget *userWidget);

    Ui::MainWindow *ui;
    SuperUser superuser;
    QString username;
    User currentUser;
    std::vector<User> userList;
    QString currentDb;
    bool openDb;
    QDockWidget *dockWidget;
    QTabWidget *showWidget;
    QPlainTextEdit *inforWidget;
    QTableWidget *absWidget;
    Logs log;
    int resNum;
};
#endif // MAINWINDOW_H
